package com.schoolET.service.admin.adminImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.schoolET.entity.Wechat;
import com.schoolET.entity.dto.WechatInfoDTO;
import com.schoolET.entity.vo.WechatInquireVO;
import com.schoolET.mapper.WechatMapper;
import com.schoolET.service.admin.IWechatService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 微信用户 服务实现类
 * </p>
 *
 * @author lin
 * @since 2024-06-04
 */
@Service
public class WechatServiceImpl extends ServiceImpl<WechatMapper, Wechat> implements IWechatService {

    @Override
    public Page<WechatInfoDTO> inquireWechat(WechatInquireVO wechatInquireVO) {
        if (wechatInquireVO.getPageNum() == null || wechatInquireVO.getPageSize() == null) {
            wechatInquireVO.setPageNum(1);
            wechatInquireVO.setPageSize(5);
        }
        Page<WechatInfoDTO> page = new Page<>(wechatInquireVO.getPageNum(), wechatInquireVO.getPageSize());
        return baseMapper.selectByNicknameAndPosition(page, wechatInquireVO.getNickName(), wechatInquireVO.getPosition());
    }

    @Override
    public Wechat selectWechatByOpenId(String openId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("open_id", openId);
        return baseMapper.selectOne(queryWrapper);
    }
}
